import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

export const exportDeptUrl = "/iam-service/dept/export"
export const importDeptUrl = "/iam-service/dept/import"


export const getDept = (params) => {
  return defHttp.get({url: '/iam-service/dept/get', params});
}

export const listDeptTree = (params) => {
  return defHttp.get({url: '/iam-service/dept/listTree', params});
}

export const saveOrUpdateDept = (params, isUpdate) => {
  let url = '/iam-service/dept/' + (isUpdate ? 'update' : 'save');
  return defHttp.post({url: url, params});
}

export const deleteDept = (params, handleSuccess) => {
  return defHttp.delete({url: '/iam-service/dept/delete', data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchDeleteDept = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({
        url: '/iam-service/dept/batchDelete', data: params
     }, { joinParamsToUrl: true }).then(() => {
        handleSuccess(); 
     });
    }
  });
}
